$(function(){
	sys.selectpicker({
		id:'status',  //select的id
		url: rootPath + "/dict/listKeyMapEntites",  //请求数据的远程地址
		param: {keyType : 'status'}, //过滤参数
		//defaultValue:{},
		valueField: 'keyValue',
		textField: 'keyIntro',
		width: '200px'});
	
	 $("#btn_save").click(function(){
			$("#roleForm").submit();
			return false;
		});
	 
	 
	//返回按钮
	$("#btn_back").on("click",function(){
		parent.opt_return_result = '0';
		sys.closeRemote();
	});
	//新增表单校验
 	$("#roleForm").validate({
 		rules: {
 			roleName:{
 				required:true,
        		minlength:3,
        		maxlength:20
        	}
 		},
 		messages: {
        	roleName:{
        		required: '请填写角色名称',
        		minlength: '角色名称至少6位',
        		maxlength: '角色名称至多20位'
        	}
 		},
 		errorPlacement: function(error, element) { //错误信息位置设置方法
 			error.insertAfter(element);
		},
 		submitHandler: function(form){
 			if (!$(form).valid()) {
				return false;
			}
 			var roleName=$("#roleName").val();
 			var status=$("#status").val();
 			var roleIntro=$("#roleIntro").val();
 			$.ajax({
 				type: 'POST',
 				url: rootPath+"/role/saveRole",
				data : {roleName:roleName,
					status:status,
					roleIntro:roleIntro
					},
				dataType: "json",
				success : function(data) {
					if(data.resultCode=='1'){
						parent.opt_return_result = '1';
 						sys.closeRemote();
 					}else{
 						parent.opt_return_result = '-1';
 						sys.closeRemote();
 					}
				}
				
			});
         }
 	});

			
				
			
    	})